﻿using BlazorLearn.Shared.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Components;

namespace BlazorLearn.Shared.Pages;
partial class UserList:ComponentBase
{
    [Inject] ApplicationDbContext Context { get; set; }


    IEnumerable<User> Users { get; set; } = Enumerable.Empty<User>();

    bool IsLoading { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await GetListAsync();
        }
    }

    async Task GetListAsync()
    {
        IsLoading = true;
        await Task.Delay(3000);
        Users = await Context.Users.ToListAsync();
        IsLoading = false;

        StateHasChanged();
    }
}
